package com.ce.webframework.sec.dao.impl;

import java.util.List;

import org.hibernate.Query;

import com.ce.webframework.sec.dao.ISecDragTargetDao;
import com.ce.webframework.sec.model.SecDragTargetDO;
import com.sitechasia.webx.core.dao.hibernate3.HibernateDomainObjectDao;

public class SecDragTargetDaoImpl extends HibernateDomainObjectDao<SecDragTargetDO> implements ISecDragTargetDao {

	/**
	 * 功能描述:取得容器集
	 * @param type  类型
	 * @param epId  企业标识
	 * @return SecDragTargetDO 集合
	 */
	@SuppressWarnings("unchecked")
	public List<SecDragTargetDO> getDragTargets(String type, Long epId){

		StringBuffer hql = new StringBuffer();
		hql.append("FROM SecDragTargetDO info");
		hql.append(" WHERE info.epId = ?");
		hql.append(" ORDER BY info.dragTargetId ASC");

		Query query = getSession().createQuery(hql.toString());
//		query.setParameter(0, type);
		query.setParameter(0, epId);
		return query.list();

	}

	/**
	 * 功能描述:通过名称取得容器
	 * @param name  类型
	 * @param epId  企业标识
	 * @return SecDragTargetDO
	 */
	public SecDragTargetDO getDragTargetByName(String name, Long epId){

		StringBuffer hql = new StringBuffer();
		hql.append("FROM SecDragTargetDO info");
		hql.append(" WHERE info.epId = ?");
		hql.append(" AND info.name = ?");

		System.out.println("hql:" + hql.toString());

		Query query = getSession().createQuery(hql.toString());
		query.setParameter(0, epId);
		query.setParameter(1, name);
		System.out.println("query.list():" + query.list().size());
		if (query.list() != null && query.list().size() > 0){

			return (SecDragTargetDO)query.list().get(0);
		}

		return null;

	}

}
